#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#include <SDL/SDL.h>

#include "GLOBALS.h"
#include "Input.h"
#include "Paint.h"
#include "Update.h"

using namespace std;

  
int main(int argc, char **argv) {
  int exit_game=0;
  enum input_type input=LEFT;
  
  // Setup the SDL surface for drawing
  SDL_Surface *screen;
  if(SDL_Init(SDL_INIT_VIDEO)!=0){
    cout << "SDL was unable to set initialize, exiting..." << endl;
  }else{
    // Make SDL quit when the program exits
    atexit(SDL_Quit);
    // Setup a hicolor video mode for a given screen size in globals.h
    screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,16,0);
    if(screen==NULL){
      cout << "SDL was unable to set the video mode, exiting..." << endl;
    }else{
      
    //////////////////////// Gameloop ////////////////
    do{
      
      input = check_input(input);
      
      exit_game = update_all(input);
      
      paint_all(screen);
      
      SDL_Delay(LOOP_DELAY);
      
    }while(exit_game==0);
    //////////////////////////////////////////////////
    }
  }     
  return exit_game;
}
